package com.toe.admin.controller;

import com.toe.business.service.BusinessInformationService;
import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.business.BusinessInfoUpdateDTO;
import com.toe.pojo.entity.business.BusinessInformation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/businessAdmin")
@Api(tags = "后台商家模块")
public class BusinessController {
    @DubboReference
    private BusinessInformationService dubboBusinessInformationService;

    @ApiOperation(value = "分页查询商家列表")
    @GetMapping("/page/{pageNum}/{pageSize}")
    @PreAuthorize("hasAuthority('toe/select')")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "pageNum",example = "1"),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", example = "5")
    })
    public JsonResult<JsonPage<BusinessInformation>> pageBusinesses(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        JsonPage<BusinessInformation> jsonPage = dubboBusinessInformationService.getBusinessListByPage(pageNum, pageSize);
        return JsonResult.ok(jsonPage);
    }

    @ApiOperation(value = "逻辑删除入驻商家")
    @PostMapping("/delete/{id}")
    @ApiImplicitParam(value = "商家id", name = "id", example = "1")
    public JsonResult<Void> logicallyRemoveBusiness(@PathVariable Long id) {
        dubboBusinessInformationService.removeBusinessInformation(id);
        return JsonResult.ok();
    }

}
